//
//  Qb_ProgressView.m
//  Cd_Qb
//
//  Created by mac on 2018/3/14.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "Qb_ProgressView.h"

@interface Qb_ProgressView()

@property (nonatomic, strong) UIView *foregroundStarView;
@property (nonatomic, strong) UIView *backgroundStarView;

@end

@implementation Qb_ProgressView

-(instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super initWithCoder:aDecoder]) {
        _Column = 0;
        [self createView];
    }
    return self;
}

-(void)createView{
    CGRect bounds = self.bounds;
    bounds.size.width = bounds.size.width *AdaptiveScale_W;
    self.bounds = bounds;
    self.foregroundStarView = [self createStarViewWithImage:@"Qb_Prpgress_Selected"];
    self.backgroundStarView = [self createStarViewWithImage:@"Qb_Prpgress_None"];
    if (_Column == 0) {
        self.foregroundStarView.frame = CGRectMake(0, 0, 0, self.bounds.size.height);
    }
    if (_Column == 1) {
        self.foregroundStarView.frame = CGRectMake(0, 0, 80*AdaptiveScale_W, self.bounds.size.height);
    }
    if (_Column == 2) {
        self.foregroundStarView.frame = CGRectMake(0, 0, 150*AdaptiveScale_W, self.bounds.size.height);
    }
    if (_Column == 3) {
        self.foregroundStarView.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    }
    [self addSubview:self.backgroundStarView];
    [self addSubview:self.foregroundStarView];
}

- (UIView *)createStarViewWithImage:(NSString *)imageName {
    
    UIView *view = [[UIView alloc] initWithFrame:self.bounds];
    view.clipsToBounds = YES;
    view.backgroundColor = [UIColor clearColor];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
    imageView.frame = self.bounds;
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [view addSubview:imageView];
    return view;
}


-(void)setColumn:(CGFloat)Column{
    _Column = Column;
    if (_Column == 0) {
        self.foregroundStarView.frame = CGRectMake(0, 0, 0, self.bounds.size.height);
    }
    if (_Column == 1) {
        self.foregroundStarView.frame = CGRectMake(0, 0, 80*AdaptiveScale_W, self.bounds.size.height);
    }
    if (_Column == 2) {
        self.foregroundStarView.frame = CGRectMake(0, 0, 150*AdaptiveScale_W, self.bounds.size.height);
    }
    if (_Column == 3) {
        self.foregroundStarView.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    }
}

@end
